<%@ page import="com.hichina.exception.InvalidTokenException" %>
<%@ page import="com.hichina.client.*" %>
<%@ page import="java.util.List" %>
<%@ page import="org.json.JSONObject" %>
<%@ page import="com.hichina.client.util.PageList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<%
    String code = request.getParameter("code");

    HiChina hiChina = new HiChina();
    Token token = hiChina.getAccessToken(code);
    if (token != null) {
        request.getSession().setAttribute("token", token);
        hiChina.setAccessToken(token.getAccessToken());
        out.println("access_token:" + token.getAccessToken());
        String uid = "";
        try {
            uid = hiChina.getUid();
            request.getSession().setAttribute("uid", uid);

            response.sendRedirect("/example.jsp");

          /*  out.print("当前用户UID：" + uid + "<br/>");

            out.print("<br/>当前用户Mail：" + hiChina.getMail(uid) + "<br/>");
//            out.print("当前用户状态：" + hiChina.getAccountStatus(uid) + "(0:已购买，1：试用)<br/>");


            Account account = hiChina.getAccountDetail(uid);
            out.println("<br/>当前账户信息：" + account+ "<br/>");
            DomainInfo domainInfo = hiChina.getDomainInfo(uid);
            out.println("<br/>当前用户域信息：<br/>" + domainInfo);

            out.println("<br/>当前域已授权用户：<br/>" + hiChina.listValidAccount(uid));

            AccountList accountList = hiChina.listContactAccount(uid, 0, 10);
            out.println("<br/>当前用户联系人列表：<br/>" + accountList);

            List<Department> departmentList = hiChina.listDepartment(domainInfo.getDomain());
            out.println("<br>部门列表:<br>" + departmentList);
           for(Department d:departmentList){
               PageList<Account> accountPage = hiChina.listDepartmentAccount(domainInfo.getDomain(), d.getId(),0,10);
               out.println("<br>" + d.getName() +" 下用户：<br/>" + accountPage.getTotalSize());
               out.println(accountPage.getElements());
               
           }*/
        } catch (InvalidTokenException e) {
            //刷新access token
        }
    }
%>
</body>
</html>